<?php

namespace App\Console\Commands;

use Illuminate\Console\Command;
use Illuminate\Support\Facades\Redis;

class flushredis extends Command
{
    /**
     * The name and signature of the console command.
     *
     * @var string
     */
    protected $signature = 'songshu:flushredis {echo}';

    /**
     * The console command description.
     *
     * @var string
     */
    protected $description = '{echo} 0:不打印，1打印';

    /**
     * Create a new command instance.
     *
     * @return void
     */
    public function __construct()
    {
        parent::__construct();
    }

    /**
     * Execute the console command.
     *
     * @return mixed
     */
    public function handle()
    {
        $echo = $this->argument('echo');
        $keys = config('rediskey')['read:article'];
        $time     =    time()-7*24*60*60;
        foreach($keys as $key){
            $key = $key.'*';
            $datas = Redis::keys($key);
            foreach($datas as $k){
                if (strpos($key,'tuijian'))
                {
                    continue;
                }
                $affect = Redis::ZREMRANGEBYSCORE($k,-INF,$time);
                if($affect && $echo){
                    echo $affect.':'.$k."\n";
                }
            }
        }



        $keys = config('rediskey')['read:video'];
        $time     =    time()-7*24*60*60;
        foreach($keys as $key){
            $key = $key.'*';
            $datas = Redis::keys($key);
            foreach($datas as $k){
                if (strpos($key,'tuijian'))
                {
                    continue;
                }
                $affect = Redis::ZREMRANGEBYSCORE($k,-INF,$time);
                if($affect && $echo){
                    echo $affect.':'.$k."\n";
                }
                
            }
        }
    }
}
